@echo off
cls

set CLEANUP=false
set ONLY_EXTRACT=false

set SOURCE_DIRECTORY=%~dp0
set THIS_BAT_FILE=%0
set PATH_UTILITIES=%SOURCE_DIRECTORY%..\..\utilities
set LOGGER=%PATH_UTILITIES%\cmdlog.exe

if not exist %LOGGER% set STDOUT_REDIRECTED=yes

if not "%STDOUT_REDIRECTED%" == "yes" (
    set STDOUT_REDIRECTED=yes
    cmd.exe /c %THIS_BAT_FILE% %* 2>&1 | %LOGGER% 1build.log
    exit/b
) 

echo -------------------------------------------------^> BEGIN WORK

SET ARHIVATOR="C:\Program Files\7-Zip\7z"
SET ARHIVE=archive.7z

for %%a in (.) do set NAME_PRODUCT=%%~na

if exist %NAME_PRODUCT% ( 
    echo Unpacking is not required 
) ELSE ( 
    echo Unpacking ...
    if not exist %ARHIVE% ( 
        echo ERROR: archive: %ARHIVE% not exist
        exit/b
    ) ELSE (
        %ARHIVATOR% x -y %ARHIVE%
    )
) 

if "%ONLY_EXTRACT%"=="true" exit/b


cd %NAME_PRODUCT%
call build.bat
cd..

if "%CLEANUP%"=="true" (
    if exist %NAME_PRODUCT% rmdir /s /q %NAME_PRODUCT% 
) 

echo -------------------------------------------------^> END WORK

exit /b

